﻿using System.Text.Json;
using System.Text.Json.Serialization;

namespace JsonTest
{
    public class JsonDatetimeConverter : JsonConverter<DateTime>
    {
        public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            var str = reader.GetString();
            return Convert.ToDateTime(str);
        }

        public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
        {
            writer.WriteStringValue($"{value:G}");
        }
    }
}
